package com.example.springboot.controller;
import com.example.springboot.entity.UserAddress;
import com.example.springboot.service.UserAddressService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user-addresses")
public class UserAddressController {
    private final UserAddressService userAddressService;

    public UserAddressController(UserAddressService userAddressService) {
        this.userAddressService = userAddressService;
    }

    @PostMapping("/add")
    public String addUserAddress(@RequestBody UserAddress userAddress) {
        return userAddressService.addUserAddress(userAddress);
    }

    @GetMapping("/list/{userId}")
    public List<UserAddress> getUserAddresses(@PathVariable Integer userId) {
        return userAddressService.getUserAddresses(userId);
    }

    @PutMapping("/update")
    public String updateUserAddress(@RequestBody UserAddress userAddress) {
        return userAddressService.updateUserAddress(userAddress);
    }

    @DeleteMapping("/delete/{addressId}")
    public String deleteUserAddress(@PathVariable Integer addressId) {
        return userAddressService.deleteUserAddress(addressId);
    }
    @GetMapping("/default/{userId}")
    public UserAddress getDefaultAddress(@PathVariable Integer userId) {
        return userAddressService.getDefaultAddress(userId);
    }
}
